#include "MathBase.h"

#include <cmath>

double CMathBase::Pi = (double)3.141592653589793238462643383279502884L;
double CMathBase::HalfPi = (double)1.570796326794896619231321691639751442L;
double CMathBase::PiDevide180 = (double)0.017453292519943295769236907684886127L;
double CMathBase::_180DevidePi = (double)57.29577951308232087679815481410517033L;
Float CMathBase::EqualError=(Float)1e-8;

float CMathBase::Sqrt(float InValue)
{
    return sqrtf(InValue);
}
double CMathBase::Sqrt(double InValue)
{
    return sqrt(InValue);
}

float CMathBase::Mod(float A,float B)
{
    return fmodf(A,B);
}

float CMathBase::InvSqrt(float InValue)
{
    //TODO  write a fast InvSqrt
    return 1 / Sqrt(InValue);
}

double CMathBase::InvSqrt(double InValue)
{
    return 1 / Sqrt(InValue);
}

float CMathBase::DegreeToRadian(float InDegree)
{
    return InDegree / 180 * Pi;
}

double CMathBase::DegreeToRadian(double InDegree)
{
    return InDegree / 180 * Pi;
}

float CMathBase::RadianToDegree(float InRadian)
{
    return InRadian / Pi * 180;
}

double CMathBase::RadianToDegree(double InRadian)
{
    return InRadian / Pi * 180;
}


float CMathBase::Sin(float InRadian)
{
    return  sinf(InRadian);
}

double CMathBase::Sin(double InRadian)
{
    return sin(InRadian);
}

float CMathBase::Asin(float InValue)
{
    return asinf(InValue);
}

double CMathBase::Asin(double InValue)
{
    return asin(InValue);
}


float CMathBase::Cos(float InRadian)
{
    return cosf(InRadian);
}

double CMathBase::Cos(double InRadian)
{
    return cos(InRadian);
}

float CMathBase::Acos(float InRadian)
{
    return acosf(InRadian);
}

double CMathBase::Acos(double InRadian)
{
    return acos(InRadian);
}

float CMathBase::Tan(float InRadian)
{
    return tanf(InRadian);
}

double CMathBase::Tan(double InRadian)
{
    return tan(InRadian);
}

float CMathBase::Atan(float InValue)
{
    return atanf(InValue);
}

double CMathBase::Atan(double InValue)
{
    return atan(InValue);
}

float CMathBase::Atan2(float Y, float X)
{
    return atan2f(Y, X);
}

double CMathBase::Atan2(double Y, double X)
{
    return atan2(Y, X);
}

bool CMathBase::Equal(const Float A, const Float B)
{
    Float Distance = A - B;
    return Distance< EqualError&& Distance> -EqualError;
}

Float CMathBase::Pow(Float A, Float B)
{
    return powf(A, B);
}

double CMathBase::SafeDivide(double A, double B, double Error)
{
    if(B<0)
    {
        B=Min(B,-Error);
        return A/B;
    }
    else
    {
        B=Max(B,Error);
        return A/B;
    }
}
